package Java实验.实验七;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.util.Scanner;

public class SocketTest_c {
    public static void main(String[] args) throws IOException {
        // 请在Begin-End间编写代码
        /********** Begin **********/

       /* 头歌平台服务器IP 127.0.0.1
       Socket s = new Socket("127.0.0.1",9999);*/

        //本机IP 192.168.189.1
        Socket s = new Socket("192.168.189.1", 9999);

        // 获取给定的字符串
        Scanner sc = new Scanner(System.in);
        String ss = sc.nextLine();

        // 把获取的字符串发送给服务端，并接收服务端返回的消息
        OutputStream os = s.getOutputStream();
        os.write(ss.getBytes());

        InputStream is = s.getInputStream();
        byte[] bys = new byte[1024];
        int len = is.read(bys);
        System.out.println(new String(bys, 0, len));

        s.close();
        /********** End **********/

    }

}

/*测试数据：我是客户端1号 */